package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.Record;
import com.whw.fy.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Api(tags = "听课记录模块")
@RestController
@RequestMapping("/api/record")
public class RecordController {
    @Resource
    private RecordService recordService;

    @ApiOperation(value = "添加听课记录")
    @PostMapping("/one")
    public Message insert(Record record)throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (record.getRecordListenTimeToString()!=null)
            record.setRecordListentime(simpleDateFormat.parse(record.getRecordListenTimeToString()));
        return recordService.insertSelective(record);

    }



    @ApiOperation(value = "删除听课记录")
    @DeleteMapping("/")
    public Message delete(Integer recordId) {
        return recordService.deleteByPrimaryKey(recordId);
    }

    @ApiOperation(value = "修改听课记录")
    @PutMapping("/")
    public Message update(Record record) throws ParseException {
        return recordService.updateByPrimaryKeySelective(record);
    }


    @ApiOperation(value = "根据听课id获取听课记录")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer record){
        return recordService.selectByPrimaryKey(record);
    }

    @ApiOperation(value = "获得所有听课记录")
    @GetMapping("/all")
    public Message selectAll(){
        return recordService.selectAll();
    }

    @ApiOperation(value = "根据学生id获得学生听课信息")
    @GetMapping("/selectByStudentId")
    public Message selectByRecordStudentId(int studentId){return  recordService.selectByRecordStudentId(studentId);
    }

    @ApiOperation(value = "根据听课id下载听课记录")
    @GetMapping("/downloadByPrimaryKey")
    public Message downloadByPrimaryKey(String studentId) throws Exception {return  recordService.downloadByPrimaryKey(studentId);

    }

    @ApiOperation(value = "读取Excel数据,并添加")
    @GetMapping("/insertByReadExcel")
    public Message insertByReadExcel(String fileUrl) throws Exception {
        return  recordService.insertByReadExcel(fileUrl);
    }




}
